<template>
  <div class="result-container">
    <header-box :name="'搜索结果'" ></header-box>
    <div v-show="flag" class="re-y wid">
        <img src="../../assets/images/404.png" alt="">
        <van-button type="danger" size="large" @click="goback()">重新搜索</van-button>
    </div>
    <h1 v-show="!flag" class="re-no wid index-tit">共查找到 <b>{{num}}</b>处结果 </h1>
        <ul class="hot-container wid">
   
      <li v-for="item in resulelist" :key="item.id" @click="goArticle(item.id)">
        <div class="img-box">
          <img :src="item.albums[0]" alt="">
        </div>
        <h4>{{item.title}}</h4>
        <p>
          <span>
            <i class="iconfont icondengji"></i>
            {{item.tags}}
          </span>
          <span>
            点击<b>{{item.id}}</b>次
          </span>
        </p>
      </li>

    </ul>
  </div>
</template>
<script>
import Header from "../../components/tabbar/Header.vue"
  export default {
    data() {
      return {
        cartlist: [],
        resulelist:[],
        flag:true,
        sname:this.$route.params.name,
        num:0,
      }
    },
    created() {
      this.Getlist();
    },
    methods: {
      Getlist() {
        this.$http.get("json/cart/cart-list.json").then(result => {
          if (result.body.resultcode == 200) {
            this.cartlist = result.body.result.data;
              for (var i = 0; i < this.cartlist.length; i++) {
              this.cartlist[i].tags = this.cartlist[i].tags.slice(0, 5)+'...';
              if(this.cartlist[i].title.indexOf(this.sname) != -1 ){
                  this.resulelist.push(this.cartlist[i]);
                  this.num=this.resulelist.length;
                  this.flag=false
              }
            }
          } else {
            Toast("数据加载失败");
          }
        });
      },
      goArticle(id){
        this.$router.push('/cart/article/'+id)
      },
        goback() {
        this.$router.go(-1)
      }
    },
    components:{
      "header-box":Header
    }

  }

</script>
<style lang="scss" scoped>


</style>
